home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / EDITSDI.PAK / INIT.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  6KB  |  183 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   init.c
  9. //
  10. //  PURPOSE:   Performs application and instance specific initialization.
  11. //
  12. //  FUNCTIONS:
  13. //    InitApplication() - Initializes window data and registers window.
  14. //    InitInstance() - Saves instance handle and creates main window.
  15. //
  16. //  COMMENTS:
  17. //
  18.  
  19. #include <windows.h>            // required for all Windows applications
  20. #ifdef WIN16
  21. #include "win16ext.h"           // required only for win16 applications
  22. #endif
  23. #include "globals.h"            // prototypes specific to this application
  24. #include "resource.h"
  25.  
  26. HINSTANCE hInst;                // current instance
  27. HWND      hwndMain;             // main window handle
  28. char szAppName[9];              // The name of this application
  29. char szTitle[40];               // The title bar text
  30.  
  31. //
  32. //  FUNCTION: InitApplication(HINSTANCE)
  33. //
  34. //  PURPOSE: Initializes window data and registers window class.
  35. //
  36. //  PARAMETERS:
  37. //    hInstance - The handle to the instance of this application that
  38. //          is currently being executed.
  39. //
  40. //  RETURN VALUE:
  41. //    TRUE - Success
  42. //    FALSE - Initialization failed
  43. //
  44. //  COMMENTS:
  45. //
  46. //    This function is called at initialization time only if no other
  47. //    instances of the application are running.  This function performs
  48. //    initialization tasks that can be done once for any number of running
  49. //    instances.
  50. //
  51. //    In this case, we initialize a window class by filling out a data
  52. //    structure of type WNDCLASS and calling the Windows RegisterClass()
  53. //    function.  Since all instances of this application use the same
  54. //    window class, we only need to do this when the first instance is
  55. //    initialized.
  56. //
  57.  
  58. BOOL InitApplication(HINSTANCE hInstance)
  59. {
  60.     #ifdef WIN16
  61.     WNDCLASS  wc;
  62.     #else
  63.     WNDCLASSEX wc;
  64.     #endif
  65.  
  66.     // Load the application name and description strings.
  67.  
  68.     LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
  69.     LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
  70.  
  71.     // Fill in window class structure with parameters that describe the
  72.     // main window.
  73.  
  74.     #ifndef WIN16
  75.     wc.cbSize        = sizeof(WNDCLASSEX);
  76.     wc.hIconSm       = LoadImage(hInstance,        // Load small icon image
  77.                                  MAKEINTRESOURCE(IDI_APPICON),
  78.                                  IMAGE_ICON,
  79.                                  16, 16,
  80.                                  0);
  81.     #endif
  82.     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  83.     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
  84.     wc.cbClsExtra    = 0;                       // No per-class extra data.
  85.     wc.cbWndExtra    = 0;                       // No per-window extra data.
  86.     wc.hInstance     = hInstance;               // Owner of this class
  87.     wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON)); // Icon name from .RC
  88.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
  89.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
  90.     wc.lpszMenuName  = szAppName;               // Menu name from .RC
  91.     wc.lpszClassName = szAppName;               // Name to register as
  92.  
  93.     // Register the window class and return FALSE if unsuccesful.
  94.  
  95.     #ifdef WIN16
  96.     if (!RegisterClass(&wc))
  97.     {
  98.         return FALSE;
  99.     }
  100.     #else
  101.     if (!RegisterClassEx(&wc))
  102.     {
  103.         if (!RegisterClass((LPWNDCLASS)&wc.style))
  104.            return FALSE;
  105.     }
  106.     #endif
  107.     //
  108.     // **TODO** Call module specific application initialization functions here.
  109.     //
  110.  
  111.     return TRUE;
  112. }
  113.  
  114.  
  115. //
  116. //  FUNCTION:  InitInstance(HINSTANCE, int)
  117. //
  118. //  PURPOSE:  Saves instance handle and creates main window.
  119. //
  120. //  PARAMTERS:
  121. //    hInstance - The handle to the instance of this application that
  122. //          is currently being executed.
  123. //    nCmdShow - Specifies how the main window is to be diplayed.
  124. //
  125. //  RETURN VALUE:
  126. //    TRUE - Success
  127. //    FALSE - Initialization failed
  128. //
  129. //  COMMENTS:
  130. //    This function is called at initialization time for every instance of
  131. //    this application.  This function performs initialization tasks that
  132. //    cannot be shared by multiple instances.
  133. //
  134. //    In this case, we save the instance handle in a static variable and
  135. //    create and display the main program window.
  136. //
  137.  
  138. BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
  139. {
  140.     // Save the instance handle in static variable, which will be used in
  141.     // many subsequence calls from this application to Windows.
  142.  
  143.     hInst = hInstance; // Store instance handle in our global variable
  144.  
  145.     // Create a main window for this application instance.
  146.     hwndMain = CreateWindow(
  147.         szAppName,              // See RegisterClass() call.
  148.         szTitle,                // Text for window title bar.
  149.         WS_OVERLAPPEDWINDOW,    // Window style.
  150.         CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,// Use default positioning
  151.         NULL,                   // Overlapped windows have no parent.
  152.         NULL,                   // Use the window class menu.
  153.         hInstance,              // This instance owns this window.
  154.         NULL                    // We don't use any data in our WM_CREATE
  155.     );
  156.  
  157.     // If window could not be created, return "failure"
  158.     if (!hwndMain)
  159.         return FALSE;
  160.  
  161.     //
  162.     // **TODO** Call module specific instance initialization functions here.
  163.     //
  164.  
  165.     // **EDITSDI** EditSDI specific initialization
  166.  
  167.     if (!InitEdit(hwndMain)) {
  168.         return FALSE;
  169.     }
  170.  
  171.     // **COMMDLG** FindReplace dialog specific initialization
  172.  
  173.     if (!InitFindReplace()) {
  174.         return FALSE;
  175.     }
  176.  
  177.     // Make the window visible; update its client area; and return "success"
  178.     ShowWindow(hwndMain, nCmdShow); // Show the window
  179.     UpdateWindow(hwndMain);         // Sends WM_PAINT message
  180.  
  181.     return TRUE;                // We succeeded...
  182. }
  183.